/// @tags: GraphwithSegTree
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <queue>

namespace BlueQuantum {

typedef long long ll;

int const N = 1e5 + 5;
ll const LLINF = 0x3f3f3f3f3f3f3f3f;

template <typename T>
inline T &read(T &x) {
  x = 0;
  bool f = false;
  short ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = true;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + (ch ^ '0'), ch = getchar();
  if (f) x = -x;
  return x;
}

struct Edge {
  int v, nxt, w;
} e[N * 19];

struct Node {
  ll dis;
  int id;
  Node(ll dis, int id) : dis(dis), id(id) {}
  inline bool operator<(Node const &rhs) const { return dis > rhs.dis; }
};

int n, q, s, cnt, out[N << 2], in[N << 2];
int e_cnt, heads[N * 9];
ll dis[N * 9];
std::priority_queue<Node> pq;

inline void add(int u, int v, int w) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt, e[e_cnt].w = w;
}

void build(int x, int l, int r) {
  if (l == r) { return out[x] = in[x] = l, void(); }
  int mid = (l + r) >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  out[x] = ++cnt, in[x] = ++cnt;
  add(in[x], in[x << 1], 0), add(in[x], in[x << 1 | 1], 0);
  add(out[x << 1], out[x], 0), add(out[x << 1 | 1], out[x], 0);
}

void linkIn(int L, int R, int u, int w, int x = 1, int l = 1, int r = n) {
  if (L <= l && r <= R) { return add(u, in[x], w); }
  int mid = (l + r) >> 1;
  if (L <= mid) linkIn(L, R, u, w, x << 1, l, mid);
  if (mid < R) linkIn(L, R, u, w, x << 1 | 1, mid + 1, r);
}

void linkOut(int L, int R, int v, int w, int x = 1, int l = 1, int r = n) {
  if (L <= l && r <= R) { return add(out[x], v, w); }
  int mid = (l + r) >> 1;
  if (L <= mid) linkOut(L, R, v, w, x << 1, l, mid);
  if (mid < R) linkOut(L, R, v, w, x << 1 | 1, mid + 1, r);
}

inline int main() {
  (cnt = read(n)), read(q), read(s);
  build(1, 1, n);
  for (int i = 1, opt, u, v, w, l, r; i <= q; ++i) {
    read(opt);
    switch (opt) {
      case 1:
        read(u), read(v), read(w);
        add(u, v, w);
        break;
      case 2:
        read(u), read(l), read(r), read(w);
        linkIn(l, r, u, w);
        break;
      case 3:
        read(u), read(l), read(r), read(w);
        linkOut(l, r, u, w);
    }
  }
  memset(dis, 0x3f, sizeof(dis));
  dis[s] = 0;
  pq.push(Node(0, s));
  while (!pq.empty()) {
    int u = pq.top().id;
    ll d = pq.top().dis;
    pq.pop();
    if (dis[u] != d) continue;
    for (int i = heads[u], v; i; i = e[i].nxt) {
      if (dis[v = e[i].v] > dis[u] + e[i].w) {
        dis[v = e[i].v] = dis[u] + e[i].w;
        pq.push(Node(dis[v], v));
      }
    }
  }
  for (int i = 1; i <= n; ++i) { printf("%lld ", (dis[i] == LLINF) ? -1 : dis[i]); }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("CF786B Legacy.in", "r", stdin);
  freopen("CF786B Legacy.out", "w", stdout);
#endif
#endif

  return BlueQuantum::main();
}